﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Data;
using System.Data.Odbc;
using WLMCoreLibrary;

namespace WLMWebServices
{
    public class Websiteversions : BaseClass
    {
        #region private fields
        private int _idUsuarioModicifacion;
        private String _VersionNumber;
        private String _VersionZip;
        #endregion

        #region public properties
        public int idUsuarioModicifacion { get { return _idUsuarioModicifacion; } set { _idUsuarioModicifacion = value; } }
        public String VersionNumber { get { return _VersionNumber; } set { _VersionNumber = value; } }
        public String VersionZip { get { return _VersionZip; } set { _VersionZip = value; } }
        #endregion

        #region constructors
        public Websiteversions(ref dbConnector ConexionDB)
        {
            
            WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
           id = classBinder.NewRecord("WEBSITEVERSIONS");
            string queryString = "";
            queryString = "SELECT * FROM WEBSITEVERSIONS WHERE id='" + id + "'";
            GetRecord(queryString);
        }

        public Websiteversions(int registryId, ref dbConnector ConexionDB)
        {
            
            string queryString = "";
            queryString = "SELECT * FROM WEBSITEVERSIONS WHERE id='" + registryId + "'";
            WLMClassBinder classBinder = new WLMClassBinder(ref ConexionDB);
            this.GetRecord(queryString);
        }
        public Websiteversions(DataRow dataRow, ref dbConnector ConexionDB)
        {
            
            this.GetRecord(dataRow);
        }
        #endregion

        #region public methods


        public void Delete()
        {
            string queryString = "";
            queryString = "DELETE FROM WEBSITEVERSIONS WHERE id='" + id + "'";
            ConexionDBInterna.ExecuteCommand(queryString);

        }
        #endregion


        #region Private Methods
        private void GetRecord(string queryString)
        {
            OdbcDataReader reader = ConexionDBInterna.ExecuteReader(queryString);
            if (reader.HasRows)
            {
                if (!reader.IsDBNull(reader.GetOrdinal("id")))
                   id = (System.Int32)reader["id"];
                if (!reader.IsDBNull(reader.GetOrdinal("fechaCreacion")))
                   fechaCreacion = Convert.ToDateTime(reader["fechaCreacion"]);
                if (!reader.IsDBNull(reader.GetOrdinal("fechaModificacion")))
                   fechaModificacion = Convert.ToDateTime(reader["fechaModificacion"]);
                if (!reader.IsDBNull(reader.GetOrdinal("idUsuario")))
                   idUsuario = (System.Int32)reader["idUsuario"];
                if (!reader.IsDBNull(reader.GetOrdinal("idUsuarioModicifacion")))
                   idUsuarioModicifacion = (System.Int32)reader["idUsuarioModicifacion"];
                if (!reader.IsDBNull(reader.GetOrdinal("VersionNumber")))
                   VersionNumber = (System.String)reader["VersionNumber"];
                if (!reader.IsDBNull(reader.GetOrdinal("VersionZip")))
                   VersionZip = (System.String)reader["VersionZip"];
            }
        }


        private void GetRecord(DataRow dataRow)
        {
            if (dataRow != null)
            {
                if (dataRow["id"] != null)
                   id = (System.Int32)dataRow["id"];
                if (dataRow["fechaCreacion"] != null)
                   fechaCreacion = (System.DateTime)dataRow["fechaCreacion"];
                if (dataRow["fechaModificacion"] != null)
                   fechaModificacion = (System.DateTime)dataRow["fechaModificacion"];
                if (dataRow["idUsuario"] != null)
                   idUsuario = (System.Int32)dataRow["idUsuario"];
                if (dataRow["idUsuarioModicifacion"] != null)
                   idUsuarioModicifacion = (System.Int32)dataRow["idUsuarioModicifacion"];
                if (dataRow["VersionNumber"] != null)
                   VersionNumber = (System.String)dataRow["VersionNumber"];
                if (dataRow["VersionZip"] != null)
                   VersionZip = (System.String)dataRow["VersionZip"];
            }
        }


        protected override void UpdateBind()
        {
            StringBuilder strCommand = new StringBuilder();
            strCommand.Append("UPDATE WEBSITEVERSIONS set ");
            strCommand.Append("fechaModificacion='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
            strCommand.Append(",idUsuarioModicifacion='" + idUsuarioModicifacion.ToString() + "'");
            strCommand.Append(",VersionNumber=\"" + WLMFunctions.comillas(this._VersionNumber) + "\"");
            strCommand.Append(",VersionZip=\"" + WLMFunctions.comillas(this._VersionZip) + "\"");
            strCommand.Append(" WHERE id='" + id + "'");
            ConexionDBInterna.ExecuteCommand(strCommand.ToString());
        }
        #endregion
    }




    public class WebsiteversionsCollection
    {

        public List<Websiteversions> Elementos { get; set; }
        public WebsiteversionsCollection()
        {
        }
        public WebsiteversionsCollection(ref dbConnector ConexionDB)
        {
            
            string strCommand = "SELECT id FROM WEBSITEVERSIONS ";
            OdbcDataReader dataReader = ConexionDB.ExecuteReader(strCommand);
            Elementos = new List<Websiteversions>();
            while (dataReader.Read())
            {
                Websiteversions newItem = new Websiteversions(Convert.ToInt32(dataReader["id"]), ref ConexionDB);
               Elementos.Add(newItem);
            }
            dataReader.Close();
            dataReader.Dispose();
        }
    }
}